-
Notifications
You must be signed in to change notification settings - Fork 1k
Document that GetUserProfileDirectory
sets the size of the path written on success
#1810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document that GetUserProfileDirectory
sets the size of the path written on success
#1810
Conversation
@ChrisDenton : Thanks for your contribution! The author(s) have been notified to review your proposed change. |
Hello, @jwmsft seems to not be responding and this has lain fallow for a year. Can we get a review from someone else? @drewbatgit or @stevewhims perhaps? |
Cc @cgettys-microsoft @sivadeilra -- this came up when discussing the semantics of a Miri shim.
FWIW this function has been un-deprecated in the mean time. |
FWIW - I believe that the SAL annotations actually do match the semantics that the proposed documentation update suggests (edit: corrected misreading of the annotations) (from a recent userenv.h on my local dev machine - e.g. "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\UserEnv.h"). SAL reference: https://learn.microsoft.com/en-us/cpp/code-quality/annotating-function-parameters-and-return-values?view=msvc-170 //=============================================================================
//
// GetUserProfileDirectory
//
// Returns the path to the root of the requested user's profile
//
// hToken - User's token returned from LogonUser()
// lpProfileDir - Receives the path
// lpcchSize - Size of lpProfileDir
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
// Note: If lpProfileDir is not large enough or NULL, the function will fail,
// and lpcchSize will contain the necessary buffer size.
//
// Example return value: C:\Users\Joe
//
//=============================================================================
USERENVAPI
BOOL
WINAPI
GetUserProfileDirectoryA(
_In_ HANDLE hToken,
_Out_writes_opt_(*lpcchSize) LPSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
USERENVAPI
BOOL
WINAPI
GetUserProfileDirectoryW(
_In_ HANDLE hToken,
_Out_writes_opt_(*lpcchSize) LPWSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
#ifdef UNICODE
#define GetUserProfileDirectory GetUserProfileDirectoryW
#else
#define GetUserProfileDirectory GetUserProfileDirectoryA
#endif // !UNICODE |
Actually, I might be slightly misreading this - it may be that technically the SAL annotations don't go quite far enough - but that may just be because the annotations are pretty verbose to be that precise with: |
The implementation meets the requirement that you want -- on successful return, This is strongly implied by the SAL annotations. I've checked the implementation and it guarantees this contract. |
… r=ChrisDenton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? `@ChrisDenton` Fixes rust-lang#141254
… r=ChrisDenton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? ``@ChrisDenton`` Fixes rust-lang#141254
… r=ChrisDenton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? ```@ChrisDenton``` Fixes rust-lang#141254
Rollup merge of #141405 - RalfJung:GetUserProfileDirectoryW, r=ChrisDenton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? ```@ChrisDenton``` Fixes #141254
…enton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? ```@ChrisDenton``` Fixes #141254
… r=ChrisDenton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? ```@ChrisDenton``` Fixes rust-lang#141254
It was discovered that this undocumented behaviour was being relied on by a long deprecated Rust stdlib function.
In confirming this behaviour applied to both
GetUserProfileDirectoryW
andGetUserProfileDirectoryA
, I found that theA
function, unlike theW
function, was not returningTRUE
on success. Instead it also returns the size written to the buffer. I'm not sure if that part should be documented so I just changed the success case to nonzero and failure to zero.